package MyFile;

import java.io.File;

public class demo9 {
    //文件搜索
    public static void main(String[] args) {
        findFile("D:\\","WeChat.exe");
    }

    public static void findFile(String path,String name){
        File file = new File(path);
        //判断该文件是否是文件或者文件本来就不存在
        if ( file.isFile() || !file.exists()){
            return;
        }

        File[] files = file.listFiles();
        if (files == null){
            return;
        }
        for (int i = 0; i < files.length; i++) {
            File temp = files[i];
            if (temp.isFile()){
                if (temp.getName().equals(name)){
                    System.out.println("找到目标文件了 --> " + temp.getAbsolutePath());
                    return;
                }
            }else {
                findFile(temp.getAbsolutePath(),name);
            }
        }
    }

}
